package com.hbx.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbx.commonutils.R;
import com.hbx.eduservice.entity.EduCourse;
import com.hbx.eduservice.entity.EduTeacher;
import com.hbx.eduservice.service.EduCourseService;
import com.hbx.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author hbx
 * @Date 2023/10/17 16:13
 */
@Api(tags = {"讲师前台接口管理"})
@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    /**
     * 分页查询讲师
     * @param current
     * @param limit
     * @return
     */
    @PostMapping("/getTeacherFrontList/{current}/{limit}")
    public R getTeacherFrontList(@PathVariable Long current,@PathVariable Long limit){
        Page<EduTeacher> page = new Page<>(current,limit);
        Map<String,Object> map =teacherService.getTeacherFrontList(page);
        //前端用了不同的分页，所以区别于后端分页查询，这里返回分页所有数据
        return R.ok().data(map);
    }

    /**
     * 讲师详情
     * @param teacherId
     * @return
     */
    @GetMapping("/getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        // 根据讲师id查询讲师基本信息
        EduTeacher teacher = teacherService.getById(teacherId);
        // 根据讲师id查询所有课程
        LambdaQueryWrapper<EduCourse> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EduCourse::getTeacherId,teacherId);
        List<EduCourse> courseList = courseService.list(queryWrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
